//
//  ViewController.m
//  CustomPicker
//
//  Created by Joinwe on 16/1/8.
//  Copyright © 2016年 Joinwe. All rights reserved.
//

#import "ViewController.h"

//导入头文件
#import "Flag.h"
#import "FlagView.h"


@interface ViewController ()<UIPickerViewDataSource,UIPickerViewDelegate>
@property (nonatomic, strong) UIPickerView *pickView;
@property (nonatomic, strong) NSMutableArray *pickerArray;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initControl];
    
}

#pragma mark 初始化
- (void)initControl{
    _pickerArray = [[NSMutableArray alloc] initWithCapacity:0];
    
    for (int i = 0; i < 10; i ++) {
        NSMutableDictionary *dic = [[NSMutableDictionary alloc] initWithCapacity:0];
        [dic setObject:@"箭头" forKey:@"bankName"];
        [dic setObject:@"icon_wo_arrow" forKey:@"bankIcon"];
        [_pickerArray addObject:dic];
    }
    
    _pickView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 50, 320, 200)];
    _pickView.delegate = self;
    _pickView.dataSource = self;
    _pickView.backgroundColor = [UIColor grayColor];
    [self.view addSubview:_pickView];
    
}


#pragma mark pickerView delegate && dataSource
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
    return 1;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    return self.pickerArray.count;
}

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
    FlagView *flagView = [FlagView flagViewWithPickerView:pickerView];
    flagView.flag = [Flag flagWithDictionary:self.pickerArray[row]];
    //    flagView.backgroundColor = [UIColor grayColor];
    
        NSLog(@"======%@",flagView.flag.bankName);
    
    
    return flagView;
}

- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component {
    return [FlagView flagViewHeight];
}


- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
    NSLog(@"===== %ld",row);
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}

@end
